package com.tl.commonlibrary.ui.widget;

import android.app.Activity;
import android.content.Context;
import android.support.annotation.ColorInt;
import android.support.annotation.StringRes;
import android.view.View;
import android.view.animation.Animation;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.tl.commonlibrary.R;

import razerdp.basepopup.BasePopupWindow;

/**
 * ConfirmToCancelPop
 *
 * @author lisi
 * @Describe 确认取消的pop
 * @time 2017/6/23 11:47
 **/

public class ConfirmToCancelPop extends BasePopupWindow {

    private Context context;
    LinearLayout submitBtLy;
    TextView dialogTitle;

    TextView dialogContent;

    Button dialogCancel;

    Button dialogConfirm;


    OnPopClickListener onPopClickListener;

    //监听器
    public interface OnPopClickListener {
        //确认
        void onPopConfirmClick(View view);

        //取消
        void onPopCancelClick(View view);
    }

    public ConfirmToCancelPop(Context context, boolean isShow) {
        super((Activity) context);
        this.context = context;
        init(isShow);
    }

    public OnPopClickListener getOnPopClickListener() {
        return onPopClickListener;
    }

    public void setOnPopClickListener(OnPopClickListener onPopClickListener) {
        this.onPopClickListener = onPopClickListener;
    }

    @Override
    public void showPopupWindow() {
        super.showPopupWindow();
        InputMethodManager imm = (InputMethodManager)context.getSystemService(Context.INPUT_METHOD_SERVICE);
        if (imm.isActive())
            imm.hideSoftInputFromWindow(((Activity)context).getWindow().getDecorView().getWindowToken(), 0); //强制隐藏键盘
    }

    @Override
    protected Animation initShowAnimation() {
        return null;
    }

    @Override
    public View getClickToDismissView() {
        return null;
    }

    @Override
    public View onCreatePopupView() {
        return createPopupById(R.layout.confirm_cancel_pop);
    }

    @Override
    public View initAnimaView() {
        return null;
    }

    private void init(boolean isShow) {

        dialogTitle = (TextView) findViewById(R.id.dialog_title);
        submitBtLy = (LinearLayout) findViewById(R.id.submit_bt_ly);
        dialogContent = (TextView) findViewById(R.id.dialog_content);
        dialogConfirm = (Button) findViewById(R.id.dialog_confirm);
        dialogCancel = (Button) findViewById(R.id.dialog_cancel);
        dialogCancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (onPopClickListener!=null){
                    onPopClickListener.onPopCancelClick(v);
                }
                dismiss();
            }
        });
        if (isShow) {
            submitBtLy.setVisibility(View.VISIBLE);
        } else {
            submitBtLy.setVisibility(View.GONE);

        }

        dialogConfirm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (onPopClickListener != null) {
                    onPopClickListener.onPopConfirmClick(v);
                }
                dismiss();
            }
        });
        dialogCancel.setText("取消");
        dialogConfirm.setText("确定");
    }


    public void setDialogConfirm(String dialogConfirmStr){
        dialogConfirm.setText(dialogConfirmStr);
    }

    public void setDialogConfirm(String dialogConfirmStr,@ColorInt int color){
        dialogConfirm.setText(dialogConfirmStr);
        dialogConfirm.setTextColor(color);
    }


    public void setDialogCancel(String dialogCancelStr){
        dialogCancel.setText(dialogCancelStr);

    }

    public void setDialogCancel(String dialogCancelStr,@ColorInt int color){
        dialogCancel.setText(dialogCancelStr);
        dialogCancel.setTextColor(color);
    }

    public void setDialogContentStr(String dialogContentStr) {
        dialogContent.setText(dialogContentStr);
    }
    public void setDialogContentStr(@StringRes int dialogContentResources) {
        dialogContent.setText(dialogContentResources);
    }
    public void setDialogContentStr(String dialogContentStr,@ColorInt int color) {
        dialogContent.setText(dialogContentStr);
        dialogContent.setTextColor(color);
    }

}
